#include <string>

#include "Epee.h"
#include "Global.h"
#include "Affichage.h"

Epee::Epee(Affichage& oAffichage) : oAffichage(oAffichage), imageEpee(NULL), type(EPEE_NONE)
{ 
	imageSpin = oAffichage.loadImage("data/images/link/spin.png", 0, 0, 255);
	setTypeEpee(type);	
}

TypeEpee Epee::getTypeEpee()
{ return type; }

bool Epee::setTypeEpee(TypeEpee type)
{
	string nomFichier;
	
	if (imageEpee != NULL)
	{
		SDL_FreeSurface(imageEpee);
		imageEpee = NULL;
	}

	this->type = type; 

	if (type != EPEE_NONE)
	{
		if (type == EPEE_NORMAL)
			nomFichier = "data/images/link/epee_normale.png";
		else if (type == EPEE_OR)
			nomFichier = "data/images/link/epee_or.png";

		imageEpee = oAffichage.loadImage(nomFichier.c_str(), 0, 0, 255);

		return (imageEpee != NULL) ? true : false;
	}

	return true;
}

bool Epee::hasEpee()
{ return (type != EPEE_NONE) ? true : false; }

void Epee::draw(int persoX, int persoY, TypeAnim anim, TypeDirection direction, int frame, int charge)
{    
	SDL_Rect src;
	SDL_Rect corEpee;
	int xEpee, yEpee;

	corEpee.x = corEpee.y = 0;

	getClip(src, anim, direction, frame);

	if (anim == ANIM_EPEE)
	{
		correctionMouvement(corEpee, anim, direction, frame);
		xEpee = persoX + corEpee.x ; yEpee = persoY + corEpee.y;

		switch (direction) 
		{
			case DIR_N :
				switch(frame) 
				{
					case 0 : xEpee += 11 ; yEpee +=7;  break;
					case 1 : xEpee += 8  ; yEpee -=6;  break;
					case 2 : yEpee -= 8  ;             break;
					case 3 : xEpee -= 4  ; yEpee -=6;  break;
					case 4 : xEpee -= 12 ; yEpee +=1;  break;
				}
				break;

			case DIR_S :
				switch(frame) 
				{
					case 0 : xEpee -= 5  ; yEpee += 12 ; break;
					case 1 : xEpee -= 6  ; yEpee += 12 ; break;
					case 2 : xEpee += 9  ; yEpee += 21 ; break;
					case 3 : xEpee += 10 ; yEpee += 17 ; break;
					case 4 : xEpee += 16 ; yEpee += 15 ; break;
				}
				break;

			case DIR_O :
				switch(frame) 
				{
					case 0 : xEpee -= 2  ; yEpee += 1 ;  break;
					case 1 : xEpee -= 10 ;               break;
					case 2 : xEpee -= 13 ; yEpee += 13 ; break;
					case 3 : xEpee -= 12 ; yEpee += 16 ; break;
					case 4 : xEpee -= 7  ; yEpee += 21 ; break;
				}
				break;

			case DIR_E :
			   switch(frame) 
			   {
					case 0 : xEpee += 15 ; yEpee++     ; break;
					case 1 : xEpee += 15 ;               break;
					case 2 : xEpee += 16 ; yEpee += 13 ; break;
					case 3 : xEpee += 16 ; yEpee += 16 ; break;
					case 4 : xEpee += 9  ; yEpee += 21 ; break;
				}
				break;
		}
	}
	else if (anim == ANIM_CHARGE)
	{

		correctionMouvement(corEpee, anim, direction, frame);
		xEpee = persoX + corEpee.x ; yEpee = persoY + corEpee.y;

		switch (direction) 
		{
			case DIR_N : xEpee +=  4 ; src.w =  8 ; src.h = 12; break;
			case DIR_S : xEpee +=  8 ; src.w =  8 ; src.h = 12; break;
			case DIR_O : xEpee -=  8 ; src.w = 12 ; src.h =  8; break;
			case DIR_E : xEpee += 12 ; src.w = 12 ; src.h =  8; break;
		}
	}
	else if (anim  ==  ANIM_SPIN)
	{
		switch (direction) 
		{
			case DIR_N :
				if ( frame == 0 || frame == 5 || (frame >= 21 && frame <= 26) )
					{ getClipSpin(src, 0); positionEpeeSpin(corEpee, 0); }
				if (frame >= 1 && frame <= 4) 
					{ getClipSpin(src, 1); positionEpeeSpin(corEpee, 1); }
				if (frame == 6) 
					{ getClipSpin(src, 2); positionEpeeSpin(corEpee, 2); }
				if (frame == 7 || frame == 8) 
					{ getClipSpin(src, 3); positionEpeeSpin(corEpee, 3); }
				if (frame == 9 || frame == 10) 
					{ getClipSpin(src, 4); positionEpeeSpin(corEpee, 4); }
				if (frame == 11 || frame == 12) 
					{ getClipSpin(src, 5); positionEpeeSpin(corEpee, 5); }
				if (frame == 13 || frame == 14) 
					{ getClipSpin(src, 6); positionEpeeSpin(corEpee, 6); }
				if (frame == 15 || frame == 16) 
					{ getClipSpin(src, 7); positionEpeeSpin(corEpee, 7); }
				if (frame == 17 || frame == 18) 
					{ getClipSpin(src, 1); positionEpeeSpin(corEpee, 8); }
				if (frame == 19 || frame == 20) 
					{ getClipSpin(src, 0); positionEpeeSpin(corEpee, 9); }
				break;

			case DIR_S :
				if ( frame == 0 || frame == 5 || (frame >= 21 && frame <= 26) )
				{ 
					getClipSpin(src, 5);
					corEpee.x+=13 ; corEpee.y-=2;
				}
				if (frame >= 1 && frame <= 4) 
				{ 
					getClipSpin(src, 4);
					corEpee.x+=7 ; corEpee.y-=6;
				}
				if (frame == 6) 
					{ getClipSpin(src, 6); positionEpeeSpin(corEpee, 6); }
				if (frame == 7 || frame == 8)
					{ getClipSpin(src, 7); positionEpeeSpin(corEpee, 7); }
				if (frame == 9 || frame == 10) 
					{ getClipSpin(src, 1); positionEpeeSpin(corEpee, 8); }
				if (frame == 11 || frame == 12) 
					{ getClipSpin(src, 0); positionEpeeSpin(corEpee, 9); }
				if (frame == 13 || frame == 14) 
					{ getClipSpin(src, 2); positionEpeeSpin(corEpee, 2); }
				if (frame == 15 || frame == 16) 
					{ getClipSpin(src, 3); positionEpeeSpin(corEpee, 3); }
				if (frame == 17 || frame == 18) 
					{ getClipSpin(src, 4); positionEpeeSpin(corEpee, 4); }
				if (frame == 19 || frame == 20) 
					{ getClipSpin(src, 5);; positionEpeeSpin(corEpee, 5); }
				break;

			case DIR_O : 
				if ( frame == 0 || frame == 5 || (frame >= 21 && frame <= 26) )
				{ 
					getClipSpin(src, 7);
					corEpee.x+=11 ; corEpee.y+=16;
				}
				if (frame >= 1 && frame <= 4) 
				{ 
					getClipSpin(src, 6);
					corEpee.x+=13 ; corEpee.y+=9;
				}
				if (frame == 6) 
					{ getClipSpin(src, 1); positionEpeeSpin(corEpee, 8); }
				if (frame == 7 || frame == 8) 
					{ getClipSpin(src, 0); positionEpeeSpin(corEpee, 9); }
				if (frame == 9 || frame == 10) 
					{ getClipSpin(src, 2); positionEpeeSpin(corEpee, 2); }
				if (frame == 11 || frame == 12) 
					{ getClipSpin(src, 3); positionEpeeSpin(corEpee, 3); }
				if (frame == 13 || frame == 14) 
				{ 
					getClipSpin(src, 4);
					corEpee.x+=1 ; corEpee.y-=4;
				}
				if (frame == 15 || frame == 16) 
					{ getClipSpin(src, 5); positionEpeeSpin(corEpee, 5); }
				if (frame == 17 || frame == 18) 
					{ getClipSpin(src, 6); positionEpeeSpin(corEpee, 6); }
				if (frame == 19 || frame == 20) 
					{ getClipSpin(src, 7); positionEpeeSpin(corEpee, 7); }
				break;

			case DIR_E :
				if ( frame == 0 || frame == 5 || (frame >= 21 && frame <= 26) )
				{ 
					getClipSpin(src, 3);
					corEpee.x-=8 ; corEpee.y+=6;
				}
				if (frame >= 1 && frame <= 4) 
				{ 
					getClipSpin(src, 2);
					corEpee.x-=8 ; corEpee.y+=12;
				}
				if (frame == 6) 
					{ getClipSpin(src, 4); positionEpeeSpin(corEpee, 4); }
				if (frame == 7 || frame == 8) 
					{ getClipSpin(src, 5); positionEpeeSpin(corEpee, 5); }
				if (frame == 9 || frame == 10) 
					{ getClipSpin(src, 6); positionEpeeSpin(corEpee, 6); }
				if (frame == 11 || frame == 12) 
					{ getClipSpin(src, 7); positionEpeeSpin(corEpee, 7); }
				if (frame == 13 || frame == 14) 
					{ getClipSpin(src, 1); positionEpeeSpin(corEpee, 8); }
				if (frame == 15 || frame == 16) 
					{ getClipSpin(src, 0); positionEpeeSpin(corEpee, 9); }
				if (frame == 17 || frame == 18) 
					{ getClipSpin(src, 2); positionEpeeSpin(corEpee, 2); }
				if (frame == 19 || frame == 20) 
					{ getClipSpin(src, 3); positionEpeeSpin(corEpee, 3); }
		}	

		xEpee = persoX + corEpee.x ; yEpee = persoY + corEpee.y;
	}

	oAffichage.applySurface(xEpee, yEpee, imageEpee, &src);

	if (anim == ANIM_CHARGE)
		drawEtoilesCharge(xEpee, yEpee, direction, charge);
	else if (anim == ANIM_SPIN)
		drawEtoilesSpin(persoX, persoY, direction, frame);
}

void Epee::drawEtoilesCharge(int xEpee, int yEpee, TypeDirection direction, int charge)
{
	SDL_Rect src;

	if (charge < MAX_CHARGE) 
	{
		src.x = 18; src.y = 14; src.w = 7; src.h = 7;

		switch (direction) 
		{
			case DIR_N : 
				xEpee += (charge / 3) - 6 + ((charge + 2) % 3); 
				yEpee -= (charge / 2) - 5; break;

			case DIR_S : 
				xEpee -= (charge / 3) - 2 + ((charge + 2) % 3); 
				yEpee += (charge / 2); break;

			case DIR_O : 
				xEpee -= (charge / 2) - 5;
				yEpee += ((charge + 2) % 3) - 2; break;

			case DIR_E : 
				xEpee += (charge / 2);
				yEpee += ((charge + 2) % 3) - 2; break;
		}
        
		oAffichage.applySurface(xEpee, yEpee, imageSpin, &src);
        
		src.x = 5; src.y = 16; src.w = 5; src.h = 5;
        
		switch (direction) 
		{
            case DIR_N : 
				xEpee -= (charge % 3) - 1; 
				yEpee += 4; break;

            case DIR_S : 
				xEpee += (charge % 3) - 1; 
				yEpee -= 2; break;

            case DIR_O : 
				xEpee += 4;
				yEpee += (charge % 3) - 1; break;

            case DIR_E : 
				xEpee -= 2;
				yEpee += (charge % 3) - 1; break;
        }
        
		oAffichage.applySurface(xEpee, yEpee, imageSpin, &src);
    }
	else if (charge == MAX_CHARGE)
	{
		src.x = 0; src.y = 8; src.w = 8; src.h = 8;

		switch (direction) 
		{
			case DIR_N : 
				xEpee -= 2; yEpee -= 5; 

			case DIR_S : 
				xEpee -= 4; yEpee += 9; break;

			case DIR_O : 
				xEpee -= 7; yEpee -= 2; break;

			case DIR_E : 
				xEpee += 12; yEpee -= 2; break;
		}

		oAffichage.applySurface(xEpee, yEpee, imageSpin, &src);
	}
}

void Epee::drawEtoilesSpin(int persoX, int persoY, TypeDirection direction, int frame)
{
	SDL_Rect src;

    switch (frame) {
        case 0 :
            src.x = 5; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 7; persoY -= 8;}
            if (direction == DIR_S) { persoX += 6; persoY += 30;}
            if (direction == DIR_O) { persoX -= 12; persoY += 17;}
            if (direction == DIR_E) { persoX += 23; persoY += 15;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 1 :
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 9; persoY -= 6;}
            if (direction == DIR_S) { persoX += 8; persoY += 32;}
            if (direction == DIR_O) { persoX -= 10; persoY += 19;}
            if (direction == DIR_E) { persoX += 25; persoY += 17;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 0; src.y = 0; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 3; persoY += 35;}
            if (direction == DIR_S) { persoX -= 5; persoY -= 44;}
            if (direction == DIR_O) { persoX += 32; persoY -= 13;}
            if (direction == DIR_E) { persoX -= 38; persoY -= 1;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 2 :
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 9; persoY -= 6;}
            if (direction == DIR_S) { persoX += 8; persoY += 32;}
            if (direction == DIR_O) { persoX -= 10; persoY += 19;}
            if (direction == DIR_E) { persoX += 25; persoY += 17;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 8; src.y = 0; src.w = 14; src.h = 14;
            if (direction == DIR_N) { persoX -= 6; persoY += 32;}
            if (direction == DIR_S) { persoX -= 8; persoY -= 47;}
            if (direction == DIR_O) { persoX += 29; persoY -= 16;}
            if (direction == DIR_E) { persoX -= 41; persoY -= 4;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 3 :
            src.x = 8; src.y = 0; src.w = 14; src.h = 14;
            if (direction == DIR_N) { persoX += 3; persoY += 26;}
            if (direction == DIR_S) { persoY -= 15;}
            if (direction == DIR_O) { persoX += 19; persoY += 3;}
            if (direction == DIR_E) { persoX -= 15; persoY += 13;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 4 :
        case 5 :
            src.x = 22; src.y = 0; src.w = 14; src.h = 14;
            if (direction == DIR_N) { persoX += 3; persoY += 26;}
            if (direction == DIR_S) { persoY -= 15;}
            if (direction == DIR_O) { persoX += 19; persoY += 3;}
            if (direction == DIR_E) { persoX -= 15; persoY += 13;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 6 :
            src.x = 36; src.y = 0; src.w = 16; src.h = 16;
            if (direction == DIR_N) { persoX += 2; persoY += 25;}
            if (direction == DIR_S) { persoX -= 1; persoY -= 15;}
            if (direction == DIR_O) { persoX += 19; persoY += 2;}
            if (direction == DIR_E) { persoX -= 17; persoY += 12;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 7 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 5; persoY += 27;}
            if (direction == DIR_S) { persoX += 17; persoY -= 6;}
            if (direction == DIR_O) { persoX += 20; persoY += 19;}
            if (direction == DIR_E) { persoX -= 13; persoY -= 1;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 8 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 11; persoY += 22;}
            if (direction == DIR_S) { persoX += 22;}
            if (direction == DIR_O) { persoX += 14; persoY += 25;}
            if (direction == DIR_E) { persoX -= 8; persoY -= 7;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 25; src.y = 14; src.w = 7; src.h = 7; 
            if (direction == DIR_N) { persoX += 7; persoY += 6;}
            if (direction == DIR_S) { persoX -= 7; persoY -= 7;}
            if (direction == DIR_O) { persoX += 7; persoY -= 7;}
            if (direction == DIR_E) { persoX -= 5; persoY += 8;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 9 :
            src.x = 10; src.y = 14; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 14; persoY += 15;}
            if (direction == DIR_S) { persoX += 23; persoY += 7;}
            if (direction == DIR_O) { persoX += 8; persoY += 28;}
            if (direction == DIR_E) { persoX -= 2; persoY -= 10;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 18; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX += 5; persoY += 9;}
            if (direction == DIR_S) { persoX -= 3; persoY -= 8;}
            if (direction == DIR_O) { persoX += 9; persoY -= 4;}
            if (direction == DIR_E) { persoX -= 8; persoY += 6;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 5; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 9; persoY += 6;}
            if (direction == DIR_S) { persoX -= 7; persoY -= 6;}
            if (direction == DIR_O) { persoX += 6; persoY -= 6;}
            if (direction == DIR_E) { persoX -= 4; persoY += 9;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 10 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 15; persoY += 7;}
            if (direction == DIR_S) { persoX += 22; persoY += 15;}
            if (direction == DIR_O) { persoY += 28;}
            if (direction == DIR_E) { persoX += 6; persoY -= 11;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
                
            src.x = 25; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX += 11; persoY += 11;}
            if (direction == DIR_S) { persoX += 1; persoY -= 9;}
            if (direction == DIR_O) persoX += 10;
            if (direction == DIR_E) { persoX -= 10; persoY += 3;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 6; persoY += 8;}
            if (direction == DIR_S) { persoX -= 4; persoY -= 7;}
            if (direction == DIR_O) { persoX += 9; persoY -= 4;}
            if (direction == DIR_E) { persoX -= 6; persoY += 6;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 11; persoY += 6;}
            if (direction == DIR_S) { persoX -= 5; persoY -= 4;}
            if (direction == DIR_O) { persoX += 7; persoY -= 7;}
            if (direction == DIR_E) { persoX -= 3; persoY += 10;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 11 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 13;}
            if (direction == DIR_S) { persoX += 18; persoY += 22;}
            if (direction == DIR_O) { persoX -= 7; persoY += 25;}
            if (direction == DIR_E) { persoX += 13; persoY -= 9;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 25; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX -= 2; persoY += 10;}
            if (direction == DIR_S) { persoX += 5; persoY -= 8;}
            if (direction == DIR_O) { persoX += 9; persoY += 4;}
            if (direction == DIR_E) { persoX -= 9; persoY -= 1;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 3; persoY += 10;}
            if (direction == DIR_S) { persoY -= 9;}
            if (direction == DIR_O) { persoX += 11; persoY -= 1;}
            if (direction == DIR_E) { persoX -= 8; persoY += 3;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 9; persoY += 9;}
            if (direction == DIR_S) { persoX -= 3; persoY -= 7;}
            if (direction == DIR_O) { persoX += 9; persoY -= 4;}
            if (direction == DIR_E) { persoX -= 6; persoY += 8;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 12 :
            src.x = 10; src.y = 14; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 8; persoY -= 6;}
            if (direction == DIR_S) { persoX += 12; persoY += 27;}
            if (direction == DIR_O) { persoX -= 13; persoY += 19;}
            if (direction == DIR_E) { persoX += 19; persoY -= 4;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
                
            src.x = 18; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX -= 5; persoY += 8;}
            if (direction == DIR_S) { persoX += 8; persoY -= 6;}
            if (direction == DIR_O) { persoX += 8; persoY += 8;}
            if (direction == DIR_E) { persoX -= 7; persoY += 4;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
                
            src.x = 5; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX -= 1; persoY += 11;}
            if (direction == DIR_S) { persoX += 4; persoY -= 8;}
            if (direction == DIR_O) { persoX += 10; persoY += 3;}
            if (direction == DIR_E) { persoX -= 9; persoY -= 1;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
                
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 5; persoY += 10;}
            if (direction == DIR_S) { persoY -= 9;}
            if (direction == DIR_O) { persoX += 11; persoY -= 1;}
            if (direction == DIR_E) { persoX -= 7; persoY += 4;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 13 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 2; persoY -= 10;}
            if (direction == DIR_S) { persoX += 6; persoY += 29;}
            if (direction == DIR_O) { persoX -= 15; persoY += 12;}
            if (direction == DIR_E) { persoX += 22; persoY += 3;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
                
            src.x = 25; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX -= 8; persoY += 6;}
            if (direction == DIR_S) { persoX += 9; persoY -= 2;}
            if (direction == DIR_O) { persoX += 5; persoY += 10;}
            if (direction == DIR_E) { persoX -= 5; persoY -= 7;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
                
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX -= 4; persoY += 9;}
            if (direction == DIR_S) { persoX += 8; persoY -= 7;}
            if (direction == DIR_O) { persoX += 8; persoY += 6;}
            if (direction == DIR_E) { persoX -= 7; persoY -= 4;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
                
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 1; persoY += 11;}
            if (direction == DIR_S) { persoX += 4; persoY -= 8;}
            if (direction == DIR_O) { persoX += 12; persoY += 3;}
            if (direction == DIR_E) persoX -= 8;
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 14 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX += 6; persoY -= 11;}
            if (direction == DIR_S) { persoX -= 2; persoY += 28;}
            if (direction == DIR_O) { persoX -= 15; persoY += 4;}
            if (direction == DIR_E) { persoX += 23; persoY += 11;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
                
            src.x = 25; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX -= 10; persoY += 3;}
            if (direction == DIR_S) { persoX += 10; persoY += 2;}
            if (direction == DIR_O) { persoX += 1; persoY += 11;}
            if (direction == DIR_E) { persoX -= 2; persoY -= 9;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
                
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX -= 6; persoY += 6;}
            if (direction == DIR_S) { persoX += 10; persoY -= 4;}
            if (direction == DIR_O) { persoX += 6; persoY += 9;}
            if (direction == DIR_E) { persoX -= 4; persoY += 6;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
                
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX -= 3; persoY += 10;}
            if (direction == DIR_S) { persoX += 7; persoY -= 6;}
            if (direction == DIR_O) { persoX += 10; persoY += 6;}
            if (direction == DIR_E) { persoX -= 7; persoY -= 3;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 15 :
            src.x = 10; src.y = 14; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX += 13; persoY -= 9;}
            if (direction == DIR_S) { persoX -= 9; persoY += 24;}
            if (direction == DIR_O) { persoX -= 12; persoY -= 3;}
            if (direction == DIR_E) { persoX += 21; persoY += 18;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 18; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX -= 9; persoY -= 1;}
            if (direction == DIR_S) { persoX += 9; persoY += 6;}
            if (direction == DIR_O) { persoX -= 3; persoY += 10;}
            if (direction == DIR_E) { persoX += 2; persoY -= 8;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 5; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX -= 8; persoY += 3;}
            if (direction == DIR_S) persoX += 11;
            if (direction == DIR_O) { persoX += 3; persoY += 11;}
            if (direction == DIR_E) { persoX -= 1; persoY -= 8;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX -= 6; persoY += 8;}
            if (direction == DIR_S) { persoX += 10; persoY -= 4;}
            if (direction == DIR_O) { persoX += 7; persoY += 8;}
            if (direction == DIR_E) { persoX -= 5; persoY -= 6;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 18; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX += 18; persoY += 29;}
            if (direction == DIR_S) { persoX -= 17; persoY -= 36;}
            if (direction == DIR_O) { persoX += 30; persoY -= 19;}
            if (direction == DIR_E) { persoX -= 34; persoY += 19;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 16 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX += 19; persoY -= 4;}
            if (direction == DIR_S) { persoX -= 14; persoY += 18;}
            if (direction == DIR_O) { persoX -= 6; persoY -= 9;}
            if (direction == DIR_E) { persoX += 16; persoY += 24;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 25; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX -= 7; persoY -= 4;}
            if (direction == DIR_S) { persoX += 7; persoY += 9;}
            if (direction == DIR_O) { persoX -= 7; persoY += 9;}
            if (direction == DIR_E) { persoX += 5; persoY -= 6;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX -= 9; persoY -= 1;}
            if (direction == DIR_S) { persoX += 10; persoY += 4;}
            if (direction == DIR_O) { persoX -= 1; persoY += 10;}
            if (direction == DIR_E) { persoX += 3; persoY -= 9;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX -= 7; persoY += 4;}
            if (direction == DIR_S) { persoX += 12; persoY -= 1;}
            if (direction == DIR_O) { persoX += 4; persoY += 10;}
            if (direction == DIR_E) { persoX -= 1; persoY -= 8;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 5; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 13; persoY += 36;}
            if (direction == DIR_S) { persoX -= 10; persoY -= 39;}
            if (direction == DIR_O) { persoX += 36; persoY -= 12;}
            if (direction == DIR_E) { persoX -= 39; persoY += 14;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 17 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX += 22; persoY += 3;}
            if (direction == DIR_S) { persoX -= 15; persoY += 11;}
            if (direction == DIR_O) persoY -= 11;
            if (direction == DIR_E) { persoX += 10; persoY += 28;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 25; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX -= 5; persoY -= 7;}
            if (direction == DIR_S) { persoX += 3; persoY += 10;}
            if (direction == DIR_O) { persoX -= 9; persoY += 6;}
            if (direction == DIR_E) { persoX += 8; persoY -= 4;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX -= 7; persoY -= 4;}
            if (direction == DIR_S) { persoX += 9; persoY += 8;}
            if (direction == DIR_O) { persoX -= 4; persoY += 8;}
            if (direction == DIR_E) { persoX += 6; persoY -= 7;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX -= 8;}
            if (direction == DIR_S) { persoX += 11; persoY += 3;}
            if (direction == DIR_O) { persoY += 11;}
            if (direction == DIR_E) { persoX += 3; persoY -= 9;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            if (direction == DIR_N) { persoX += 8; persoY += 40;}
            if (direction == DIR_S) persoY -= 40;
            if (direction == DIR_O) { persoX += 40; persoY -= 4;}
            if (direction == DIR_E) { persoX -= 40; persoY += 8;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 18 :
            src.x = 10; src.y = 14; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX += 23; persoY += 11;}
            if (direction == DIR_S) { persoX -= 14; persoY += 3;}
            if (direction == DIR_O) { persoX += 8; persoY -= 11;}
            if (direction == DIR_E) { persoX += 2; persoY += 29;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 18; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX -= 2; persoY -= 9;}
            if (direction == DIR_S) { persoX -= 1; persoY += 11;}
            if (direction == DIR_O) { persoX -= 10; persoY += 2;}
            if (direction == DIR_E) { persoX += 10; persoY -= 1;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 5; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX -= 4; persoY -= 6;}
            if (direction == DIR_S) { persoX += 6; persoY += 10;}
            if (direction == DIR_O) { persoX -= 7; persoY += 6;}
            if (direction == DIR_E) { persoX += 8; persoY -= 4;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX -= 7; persoY -= 4;}
            if (direction == DIR_S) { persoX += 9; persoY += 6;}
            if (direction == DIR_O) { persoX -= 3; persoY += 9;}
            if (direction == DIR_E) { persoX += 7; persoY -= 8;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 19 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX += 21; persoY += 18;}
            if (direction == DIR_S) { persoX -= 10; persoY -= 4;}
            if (direction == DIR_O) { persoX += 15; persoY -= 8;}
            if (direction == DIR_E) { persoX -= 5; persoY += 27;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 25; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX += 2; persoY -= 8;}
            if (direction == DIR_S) { persoX -= 5; persoY += 10;}
            if (direction == DIR_O) { persoX -= 9; persoY -= 2;}
            if (direction == DIR_E) { persoX += 9; persoY += 3;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX -= 1; persoY -= 8;}
            if (direction == DIR_S) { persoX += 2; persoY += 11;}
            if (direction == DIR_O) { persoX -= 9; persoY += 3;}
            if (direction == DIR_E) { persoX += 10; persoY -= 1;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX -= 5; persoY -= 7;}
            if (direction == DIR_S) { persoX += 7; persoY += 9;}
            if (direction == DIR_O) { persoX -= 5; persoY += 6;}
            if (direction == DIR_E) { persoX += 10; persoY -= 6;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 18; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX -= 27; persoY += 30;}
            if (direction == DIR_S) { persoX += 26; persoY -= 29;}
            if (direction == DIR_O) { persoX += 26; persoY += 25;}
            if (direction == DIR_E) { persoX -= 35; persoY -= 26;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 20 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX += 16; persoY += 24;}
            if (direction == DIR_S) { persoX -= 4; persoY -= 9;}
            if (direction == DIR_O) { persoX += 21; persoY -= 2;}
            if (direction == DIR_E) { persoX -= 11; persoY += 22;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 25; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX += 5; persoY -= 6;}
            if (direction == DIR_S) { persoX -= 8; persoY += 8;}
            if (direction == DIR_O) { persoX -= 8; persoY -= 6;}
            if (direction == DIR_E) { persoX += 7; persoY += 6;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 3; persoY -= 9;}
            if (direction == DIR_S) { persoX -= 2; persoY += 10;}
            if (direction == DIR_O) { persoX -= 8; persoY -= 1;}
            if (direction == DIR_E) { persoX += 11; persoY += 3;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX -= 1; persoY -= 8;}
            if (direction == DIR_S) { persoX += 4; persoY += 11;}
            if (direction == DIR_O) { persoX -= 7; persoY += 3;}
            if (direction == DIR_E) { persoX += 11; persoY -= 2;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 5; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX -= 32; persoY += 25;}
            if (direction == DIR_S) { persoX += 31; persoY -= 22;}
            if (direction == DIR_O) { persoX += 21; persoY += 31;}
            if (direction == DIR_E) { persoX -= 28; persoY -= 31;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 21 :
            src.x = 10; src.y = 14; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX += 10; persoY += 28;}
            if (direction == DIR_S) { persoX += 2; persoY -= 12;}
            if (direction == DIR_O) { persoX += 23; persoY += 4;}
            if (direction == DIR_E) { persoX -= 14; persoY += 14;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 18; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX += 8; persoY -= 4;}
            if (direction == DIR_S) { persoX -= 9; persoY += 4;}
            if (direction == DIR_O) { persoX -= 5; persoY -= 8;}
            if (direction == DIR_E) { persoX += 5; persoY += 9;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 5; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 6; persoY -= 7;}
            if (direction == DIR_S) { persoX -= 6; persoY += 9;}
            if (direction == DIR_O) { persoX -= 6; persoY -= 4;}
            if (direction == DIR_E) { persoX += 9; persoY += 6;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 3; persoY -= 9;}
            if (direction == DIR_S) persoY += 10;
            if (direction == DIR_O) { persoX -= 8; persoY -= 1;}
            if (direction == DIR_E) { persoX += 12; persoY += 2;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            if (direction == DIR_N) { persoX -= 33; persoY += 19;}
            if (direction == DIR_S) { persoX += 35; persoY -= 13;}
            if (direction == DIR_O) { persoX += 16; persoY += 34;}
            if (direction == DIR_E) { persoX -= 19; persoY -= 33;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 22 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX += 2; persoY += 29;}
            if (direction == DIR_S) { persoX += 10; persoY -= 11;}
            if (direction == DIR_O) { persoX += 23; persoY += 12;}
            if (direction == DIR_E) { persoX -= 15; persoY += 6;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 25; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX += 10; persoY -= 1;}
            if (direction == DIR_S) persoX -= 10;
            if (direction == DIR_O) { persoX -= 1; persoY -= 9;}
            if (direction == DIR_E) { persoX += 2; persoY += 11;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 8; persoY -= 4;}
            if (direction == DIR_S) { persoX -= 8; persoY += 6;}
            if (direction == DIR_O) { persoX -= 4; persoY -= 7;}
            if (direction == DIR_E) { persoX += 6; persoY += 8;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 7; persoY -= 8;}
            if (direction == DIR_S) { persoX -= 3; persoY += 8;}
            if (direction == DIR_O) { persoX -= 6; persoY -= 4;}
            if (direction == DIR_E) { persoX += 11; persoY += 6;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 23 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 5; persoY += 27;}
            if (direction == DIR_S) { persoX += 17; persoY -= 7;}
            if (direction == DIR_O) { persoX += 20; persoY += 19;}
            if (direction == DIR_E) { persoX -= 13; persoY -= 1;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 25; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX += 9; persoY += 3;}
            if (direction == DIR_S) { persoX -= 9; persoY -= 4;}
            if (direction == DIR_O) { persoX += 3; persoY -= 8;}
            if (direction == DIR_E) { persoX -= 2; persoY += 10;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 10; persoY -= 1;}
            if (direction == DIR_S) { persoX -= 9; persoY += 2;}
            if (direction == DIR_O) { persoX -= 1; persoY -= 9;}
            if (direction == DIR_E) { persoX += 3; persoY += 10;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 10; persoY -= 6;}
            if (direction == DIR_S) { persoX -= 6; persoY += 6;}
            if (direction == DIR_O) { persoX -= 3; persoY -= 6;}
            if (direction == DIR_E) { persoX += 9; persoY += 9;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 18; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX -= 40; persoY -= 13;}
            if (direction == DIR_S) { persoX += 31; persoY += 16;}
            if (direction == DIR_O) { persoX -= 18; persoY += 33;}
            if (direction == DIR_E) { persoX += 8; persoY -= 39;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 24 :
            src.x = 10; src.y = 14; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 11; persoY += 22;}
            if (direction == DIR_S) { persoX += 22; persoY -= 1;}
            if (direction == DIR_O) { persoX += 14; persoY += 25;}
            if (direction == DIR_E) { persoX -= 8; persoY -= 7;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 18; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX += 7; persoY += 6;}
            if (direction == DIR_S) { persoX -= 7; persoY -= 7;}
            if (direction == DIR_O) { persoX += 7; persoY -= 7;}
            if (direction == DIR_E) { persoX -= 5; persoY += 8;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 5; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 11; persoY += 3;}
            if (direction == DIR_S) { persoX -= 8; persoY -= 2;}
            if (direction == DIR_O) { persoX += 3; persoY -= 8;}
            if (direction == DIR_E) { persoX -= 1; persoY += 11;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 11; persoY -= 2;}
            if (direction == DIR_S) { persoX -= 8; persoY += 3;}
            if (direction == DIR_O) persoY -= 8;
            if (direction == DIR_E) { persoX += 5; persoY += 10;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 5; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX -= 33; persoY -= 18;}
            if (direction == DIR_S) { persoX += 26; persoY += 21;}
            if (direction == DIR_O) { persoX -= 22; persoY += 28;}
            if (direction == DIR_E) { persoX += 15; persoY -= 32;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 25 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 15; persoY += 15;}
            if (direction == DIR_S) { persoX += 24; persoY += 6;}
            if (direction == DIR_O) { persoX += 7; persoY += 28;}
            if (direction == DIR_E) { persoX -= 6; persoY -= 9;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 25; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX += 5; persoY += 9;}
            if (direction == DIR_S) { persoX -= 3; persoY -= 8;}
            if (direction == DIR_O) { persoX += 9; persoY -= 4;}
            if (direction == DIR_E) { persoX -= 7; persoY += 9;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 9; persoY += 6;}
            if (direction == DIR_S) { persoX -= 7; persoY -= 6;}
            if (direction == DIR_O) { persoX += 6; persoY -= 6;}
            if (direction == DIR_E) { persoX -= 1; persoY += 10;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 12; persoY += 2;}
            if (direction == DIR_S) { persoX -= 7; persoY -= 1;}
            if (direction == DIR_O) { persoX += 4; persoY -= 9;}
            if (direction == DIR_E) { persoX += 4; persoY += 10;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            if (direction == DIR_N) { persoX -= 24; persoY -= 20;}
            if (direction == DIR_S) { persoX += 20; persoY += 24;}
            if (direction == DIR_O) { persoX -= 22; persoY += 22;}
            if (direction == DIR_E) { persoX += 18; persoY -= 28;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 26 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 16; persoY += 7;}
            if (direction == DIR_S) { persoX += 23; persoY += 14;}
            if (direction == DIR_O) { persoX -= 1; persoY += 28;}
            if (direction == DIR_E) { persoX += 7; persoY -= 12;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 25; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX += 2; persoY += 11;}
            if (direction == DIR_S) { persoX += 1; persoY -= 9;}
            if (direction == DIR_O) persoX += 10;
            if (direction == DIR_E) { persoX -= 10; persoY += 3;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 6; persoY += 8;}
            if (direction == DIR_S) { persoX -= 4; persoY -= 8;}
            if (direction == DIR_O) { persoX += 9; persoY -= 4;}
            if (direction == DIR_E) { persoX -= 6; persoY += 6;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 11; persoY += 6;}
            if (direction == DIR_S) { persoX -= 5; persoY -= 4;}
            if (direction == DIR_O) { persoX += 7; persoY -= 7;}
            if (direction == DIR_E) { persoX -= 3; persoY += 10;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 27 :
            src.x = 10; src.y = 14; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 14;}
            if (direction == DIR_S) { persoX += 19; persoY += 22;}
            if (direction == DIR_O) { persoX -= 8; persoY += 25;}
            if (direction == DIR_E) { persoX += 14; persoY -= 10;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 18; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX -= 2; persoY += 10;}
            if (direction == DIR_S) { persoX += 5; persoY -= 8;}
            if (direction == DIR_O) { persoX += 9; persoY += 4;}
            if (direction == DIR_E) { persoX -= 9; persoY -= 1;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 5; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX += 3; persoY += 10;}
            if (direction == DIR_S) persoY -= 9;
            if (direction == DIR_O) { persoX += 11; persoY -= 1;}
            if (direction == DIR_E) { persoX -= 8; persoY += 3;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 33; src.y = 15; src.w = 1; src.h = 1;
            if (direction == DIR_N) { persoX += 9; persoY += 9;}
            if (direction == DIR_S) { persoX -= 3; persoY -= 7;}
            if (direction == DIR_O) { persoX += 9; persoY -= 4;}
            if (direction == DIR_E) { persoX -= 6; persoY += 8;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            
            src.x = 18; src.y = 14; src.w = 7; src.h = 7;
            if (direction == DIR_N) { persoX -= 5; persoY -= 34;}
            if (direction == DIR_S) { persoX -= 8; persoY += 30;}
            if (direction == DIR_O) { persoX -= 35; persoY -= 4;}
            if (direction == DIR_E) { persoX += 29; persoY += 4;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 28 :
            src.x = 52; src.y = 0; src.w = 14; src.h = 14;
            if (direction == DIR_N) { persoX -= 10; persoY += 22;}
            if (direction == DIR_S) { persoX += 14; persoY -= 8;}
            if (direction == DIR_O) { persoX += 17; persoY += 17;}
            if (direction == DIR_E) { persoX -= 14; persoY -= 1;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 29 :
            src.x = 0; src.y = 8; src.w = 8; src.h = 8;
            if (direction == DIR_N) { persoX -= 7; persoY += 25;}
            if (direction == DIR_S) { persoX += 17; persoY -= 5;}
            if (direction == DIR_O) { persoX += 20; persoY += 20;}
            if (direction == DIR_E) { persoX -= 11; persoY += 2;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
        case 30 :
            src.x = 0; src.y = 16; src.w = 5; src.h = 5;
            if (direction == DIR_N) { persoX -= 6; persoY += 27;}
            if (direction == DIR_S) { persoX += 18; persoY -= 3;}
            if (direction == DIR_O) { persoX += 21; persoY += 22;}
            if (direction == DIR_E) { persoX -= 10; persoY += 4;}
            oAffichage.applySurface(persoX, persoY, imageSpin, &src);
            break;
    }
}

void Epee::correctionMouvement(SDL_Rect& corEpee, TypeAnim anim, TypeDirection direction, int frame, int clip)
{
	//On n'utilise que x et y
	corEpee.x = corEpee.y = 0;

	if (anim == ANIM_CHARGE)
	{
		switch (direction) 
		{
			case DIR_N : 
				corEpee.y -= (!frame) ? 2 : 1; 
				break;

			case DIR_S : 
				corEpee.y += (!frame) ? 19 : 20;
				break;

			case DIR_E :
			case DIR_O : 
				corEpee.y += (!frame) ? 14 : 15;
				break;
		}
	}
}

void Epee::positionEpeeSpin(SDL_Rect& posEpee, int clip)
{
	//On n'utilise que x et y
	posEpee.x = posEpee.y = 0;

	switch (clip)
	{
		case 0 : posEpee.x -=  4 ; posEpee.y += 17 ; break;
		case 1 : posEpee.x +=  3 ; posEpee.y += 20 ; break;
		case 2 : posEpee.x -= 12 ; posEpee.y += 15 ; break;
		case 3 : posEpee.x -= 12 ; posEpee.y +=  8 ; break;
		case 4 : posEpee.x++     ; posEpee.y -=  4 ; break;
		case 5 : posEpee.x += 10 ; posEpee.y -=  4 ; break;
		case 6 : posEpee.x += 16 ; posEpee.y +=  8 ; break;
		case 7 : posEpee.x += 16 ; posEpee.y += 16 ; break;
		case 8 : posEpee.x +=  7 ; posEpee.y += 21 ; break;
		case 9 : posEpee.x--     ; posEpee.y += 21 ; break;
	}
}

void Epee::getClip(SDL_Rect& src, TypeAnim anim, TypeDirection direction, int frame)
{
	switch (type) {
	case EPEE_NONE:
		break;

	case EPEE_NORMAL:
	case EPEE_OR:
		src.w = 14;
		src.h = 14;
		break;
	}
	
	if ( anim == ANIM_EPEE )
	{
		src.x = src.w * direction;
		src.y = src.h * frame;
	}
	else if ( anim == ANIM_CHARGE )
	{
		src.x = src.w * direction;
		src.y = src.h * 5;
	}
	else if ( anim == ANIM_SPIN )
	{ src.w = 12 ; src.h = 12; }
}

void Epee::getClipSpin(SDL_Rect& src, int clip)
{
	switch (clip)
	{
		case 0 : src.x = 68 ; src.y = 12 ; break;
		case 1 : src.x = 56 ; src.y = 12 ; break;
		case 2 : src.x = 56 ; src.y = 24 ; break;
		case 3 : src.x = 56 ; src.y = 36 ; break;
		case 4 : src.x = 68 ; src.y =  0 ; break;
		case 5 : src.x = 56 ; src.y =  0 ; break;
		case 6 : src.x = 68 ; src.y = 36 ; break;
		case 7 : src.x = 68 ; src.y = 24 ; break;
	}
}

Epee::~Epee() 
{
    if (imageEpee != NULL)
		SDL_FreeSurface(imageEpee);

	SDL_FreeSurface(imageSpin);
}
